<template>
  <div class="page">
    <div class="weui-cells">
       <template v-if="list.length" >
      <div class="weui-cell" v-for="(item,index) in list" :key="index" >
        <div class="weui-cell__bd d_left">
          <div>{{item.remark||''}}</div>
          <p >余额：{{item.balance}}</p>
        </div>
        <div class="weui-cell__ft d_right">
          <p>{{item.tran_time}}</p>
          <div v-if="item.tran_type==1">+{{item.tran_amount}}</div>
          <div v-if="item.tran_type==2">-{{item.tran_amount}}</div>
        </div>
      </div>
      </template>
       <div class="weui-cell" v-if="!list.length" style="display: flex;justify-content: center;">
         <span>暂无数据</span>
       </div>
    </div>
  </div>
</template>

<script>
import * as appId from "@/utils/util"
import {getTIme} from "@/utils/util"
export default {
  data () {
    return {
      current: 0,
      pageNo:1,
      pageSize:10,
      list:[],
      result:[]
    }
  },
  onShow(){
    wx.setNavigationBarTitle({
      title: "账户明细"
    })
     this.getDtail()
  },
  onPullDownRefresh(){
     console.log('down')
      if(this.result.length){
     this.pageNo++;
    }
     this.getDtail()

  },
  onReachBottom () {
    wx.showNavigationBarLoading()
    console.log('pull')
    if(this.result.length){
     this.pageNo++;
    }
    this.getDtail()
    console.log(this.pageNo)
    // wx.stopPullDownRefresh()
   },
  methods: {
    getDtail(){
       let phone=JSON.parse(wx.getStorageSync('userInfo')).mobileNo;
       let that=this;
        this.$http.request({
            method:"post",
            url:"/v1.0/appletLogin/balanceDetails",
            body:{
              "phone":phone,
              "appid":appId.appId,
              "pageNo":that.pageNo,
              "pageSize":that.pageSize
            }
        }).then((data)=>{
          if(data.code==0){
            this.result=data.result;
             data.result.forEach(element => {

                if( element.tran_time){
                  element.tran_time=getTIme(element.tran_time)
                }

              });
            // data.result.tran_time=data.result.tran_time.split(' ')[0]
             if (that.pageNo > 1) {
              that.list.push(...data.result)
                console.log(that.list)
              }else{
                that.list=data.result;
              }
            if(!data.result.length){
               wx.stopPullDownRefresh();
            //    wx.showToast({
            //   title: '暂无更多数据',
            //   icon: 'none',
            //   duration: 2000
            // })
            }



          }else{


          }
        })
    },
    bindViewTap () {
      const url = '../logs/main'
      if (mpvuePlatform === 'wx') {
        mpvue.switchTab({ url })
      } else {
        mpvue.navigateTo({ url })
      }
    }
  },

  created () {
    // let app = getApp()
  }
}
</script>

<style scoped>
.d_left,.d_right{
  line-height: 1.6em;
}
.d_left div{
  color: #333;
}
.d_left p{
  color: #666;
  font-size: 0.8em;
}
.d_right div{
  color: #333;
  font-size: 0.9em;
}
.d_right p{
  color: #999;
  font-size: 0.8em;
}
</style>
